<?php
!defined('IN_HDWIKI') && exit('Access Denied');

class control extends base{

	function control(& $get,& $post){
		$this->base( & $get,& $post);
		$this->load("synonym");
		$this->load("doc");
		$this->load("category");
		$this->load("attachment");
		$this->load("usergroup");
	}
	
	function doremovesynonym(){
		$destdid=$this->post['destdid'];
		if(is_numeric($destdid)){
			$num=$_ENV['synonym']->removesynonym($destdid);
			$this->message($num,'',2);
		}else{
			$this->message(-1,'',2);
		}
	}
	
	function doview(){
		if(!is_numeric(@$this->get[2])){
			$this->message($this->view->lang['parameterError'],'BACK',0);
		}
		$synonym=$_ENV['synonym']->get_synonym_by_src('',$this->get[2]);
		if((bool)$synonym){
			$doc=$_ENV['doc']->get_doc($synonym['destdid']);
			if(!(bool)$doc){
				$this->message($this->view->lang['parameterError'],'BACK',0);
			}
			$doc['time']=$this->date($doc['time']);
			$this->view->vars['setting']['seo_keywords']=$doc['tag'];
			$this->view->vars['setting']['seo_description']=$doc['summary'];
			$doc['tag']=$_ENV['doc']->spilttags($doc['tag']);
			$doc['lastedit']=date('Y-m-d',$doc['lastedit']);
			$recenteditor=$_ENV['doc']->get_recenteditor($doc['did'],1,$doc['authorid']);
			if (is_array($recenteditor) && count($recenteditor)>0){
				$groupinfo = $_ENV['usergroup']->get_groupinfo($recenteditor[0]['authorid']);
				$recenteditor[0]['grouptitle']= $groupinfo['grouptitle'];
				$recenteditor[0]['groupcolor']= $groupinfo['color'];
				$recenteditor[0]['editorstar']= $groupinfo['editorstar'];
				$recenteditor[0]['userimage']= $groupinfo['image'];
				$recenteditor[0]['userstars']= $groupinfo['stars'];
			}
			$similardoc=$_ENV['doc']->get_similardoc($doc['cid']);
			$category=$_ENV['category']->get_category($doc['cid']);
			$navigation=unserialize($category['navigation']);
			$attachment=$_ENV['attachment']->get_attachment('did',$doc['did']);
			$synonyms=$_ENV['synonym']->get_synonym_by_dest('',$doc['title']);
			$groupinfo = $_ENV['usergroup']->get_groupinfo($doc['authorid']);
			$doc['grouptitle']= $groupinfo['grouptitle'];
			$doc['groupcolor']= $groupinfo['color'];
			$doc['editorstar']= $groupinfo['editorstar'];
			$doc['userimage']= $groupinfo['image'];
			$doc['userstars']= $groupinfo['stars'];
			$doc['title']=$synonym['srctitle'];
			$this->view->assign('synonym',$synonym);
			$this->view->assign('synonyms',$synonyms);
			$this->view->assign('attachment',$attachment);
			$this->view->assign('attach_download',$this->checkable('attachment-download'));
			$this->view->assign('audit',$this->checkable('admin_doc-audit'));
			$this->view->assign('synonym_audit',$this->checkable('synonym-savesynonym'));
			$this->view->assign('navtitle',$doc['title'].'-'.$navigation[$num-1]['name'].'-');
			$this->view->assign("searchtext",$doc['title']);
			$this->view->assign('doc',$doc);
			$this->view->assign('recenteditor',$recenteditor);
			$this->view->assign('similardoc',$similardoc);
			$this->view->assign('navigation',$navigation);
			$this->view->display('viewsynonym');
		}else{
			$this->message($this->view->lang['parameterError'],'BACK',0);
		}
	}
	
	function dosavesynonym(){
		$synonyms=string::hiconv(trim($this->post['srctitles']));
		if(empty($synonyms)){
			$this->message($_ENV["synonym"]->encode_data(array(-1,'')),'',2);
		}
		$srctitles=array_unique(explode(',',$synonyms));
		$returnsyn=stripslashes(implode(',',$srctitles));
		$desttitle=string::hiconv(trim($this->post['desttitle']));
		$filter=$_ENV["synonym"]->is_filter($srctitles,$desttitle);
		if($filter[0]<0){
			$this->message($_ENV["synonym"]->encode_data($filter),'',2);
		}
		if(is_array($srctitles)&&is_numeric($this->post['destdid'])&&!empty($desttitle)){
			$num=$_ENV['synonym']->savesynonym($this->post['destdid'],$desttitle,$srctitles);
			$this->message($_ENV["synonym"]->encode_data(array($num,$returnsyn)),'',2);
		}else{
			$this->message($_ENV["synonym"]->encode_data(array(-1,'')),'',2);
		}
	}
}

?>